/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/11/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.manager.workflow.hander;

import org.fireflow.engine.EngineException;
import org.fireflow.engine.IProcessInstance;
import org.fireflow.engine.IWorkItem;
import org.fireflow.engine.impl.TaskInstance;
import org.fireflow.engine.taskinstance.IAssignable;
import org.fireflow.engine.taskinstance.IAssignmentHandler;
import org.fireflow.kernel.KernelException;

import com.application.usertable.entity.Usertable;
import com.manager.commons.CommonUtil;
import com.manager.commons.CurrentUserUtils;
/**
 * 该AssignmentHandler将TaskInstance分配给当前用户，并且立即结束新创建的工作项。
 * 适用于填写表单。
 * 
 * @author 王浩 QQ：873987060   
 *
 */
public class CurrentUserAssignmentHandler implements IAssignmentHandler {
    
	private String ROLE_YFJL = "研发经理";
	@Override
	public void assign(IAssignable able, String role) throws EngineException,KernelException {
		//取得当前系统用户
		Usertable user = CurrentUserUtils.getCurrentUser();
		//为当前用户创建WorkItem
		IWorkItem wi = able.asignToActor(user.getId());
		//签收和完成工作项目使得流程往下走
		wi.claim();
		IProcessInstance processInstance = ((TaskInstance)wi.getTaskInstance()).getAliveProcessInstance();
		String pathFlag = "one";
		if(user!=null){
			if(CommonUtil.isZXFZR(user.getId())){
				pathFlag = "three";
			}
			if(CommonUtil.isYFJL(user.getId())){
				pathFlag = "two";
			}
		}
		processInstance.setProcessInstanceVariable("pathFlagRole", pathFlag);
		processInstance.setProcessInstanceVariable("approveFlag", "agree");
		wi.complete();
	}

}
